package com.base.exception;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @类描述：业务异常
 * @创建人：wangdw
 * @创建时间：2019年2月25日 下午2:38:08
 */
@SuppressWarnings("serial")
public class BusinessException extends RuntimeException {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    
    public BusinessException() {
        super();
    }
    
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        logger.error(message, cause);
    }
    
    public BusinessException(String message) {
        super(message);
        logger.error(message);
    }
    
    public BusinessException(Throwable cause) {
        super(cause);
    }
    
    /**
     * 方法描述：统一输出异常，以后好对异常统一处理
     * @param msg
     * @param t
     */
    public static void error(String msg, Throwable t) {
        new BusinessException(msg, t);
        // TODO
    }
    
    /**
     * 方法描述：不是很重要的异常
     * @param msg
     * @param t
     */
    public static void info(String msg, Throwable t) {
        new BusinessException(msg, t);
    }
    
    public static String getStackTrace(Throwable t) {
        Writer result = new StringWriter();
        PrintWriter printWriter = new PrintWriter(result);
        t.printStackTrace(printWriter);
        return result.toString();
    }
}
